<?php

class BMode_view extends BMode
{
    
    /**
     * SMARTY模板
     */
    const ENGINE_SMARTY = 'smarty';
    
    /**
     * 当前支持的缓存引擎
     *
     * @access private
     * @var array
     */
    private $_engines = array(self::ENGINE_SMARTY);
    
    /**
     * 当前引擎
     *
     * @access private
     * @var string
     */
    private $_engine = self::ENGINE_SMARTY;
    
    /**
     * 对象实例容器
     *
     * @access private
     * @var array
     */
    private static $_container = array();
    
    /**
     * 构造
     *
     * @access public
     * @return null
     */
    function __construct()
    {
        $this->engine(self::ENGINE_SMARTY);
    }
    
    /**
     * 设置/取得引擎
     *
     * @access public
     * @param $engine string           
     * @return mixed
     */
    function engine($engine = null)
    {
        if (is_null($engine)) {
            return $this->_engine;
        } elseif (!in_array($engine, $this->_engines)) {
            throw new DViewException('engine_unsupported', $engine);
        }
        $this->_engine = $engine;
        return $this;
    }
    
    /**
     * 获取引擎
     *
     * @access public
     * @param $engine string           
     * @return object
     */
    function pick($engine = null)
    {
        if (!is_null($engine)) {
            $this->engine($engine);
        }
        if ($instance = self::$_container[$this->_engine]) {
            return $instance;
        } elseif (!($instance = BLoader::instance("../Mode_view_{$this->_engine}"))) {
            throw new BViewException('component_import_failed', $this->_engine);
        }
        self::$_container[$this->_engine] = $instance;
        
        return $instance;
    }

}

interface DIView
{
    
    /**
     * 赋值
     *
     * @access public
     * @param $var string           
     * @param $val mixed           
     * @return object
     */
    function set($var, $val = null);
    
    /**
     * 取值
     *
     * @access public
     * @param $var string           
     * @return mixed
     */
    function get($var = null);
    
    /**
     * 呈现
     *
     * @access public
     * @param $template string           
     * @param $fetch bool           
     * @return string
     */
    function display($template = null, $fetch = false);

}

?>
